package com.njmt.cloud.msprovder.controller;


import com.njwt.cloud.mscommon.support.ApiResponse;
import com.njwt.cloud.mscommon.support.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.*;

/**
 * @author <a href="mailto:xingxiaofeng@gtmap.cn">xingxiaofeng</a>
 * @date 2022-06-22
 * @desc RolesController
 */
@RestController
@RequestMapping("role")
@Api(tags = "角色管理")
public class RolesController extends BaseController{
    @ApiOperation(value = "添加角色管理-后端管理角色管理", notes = "添加角色管理-后端管理角色管理")
    @PreAuthorize("hasAuthority('role_add')")
    @PostMapping("/add")
    public ApiResponse add() {
        return  success();
    }

    @ApiOperation(value = "修改角色管理-后端管理角色管理", notes = "修改角色管理-后端管理角色管理")
    @PreAuthorize("hasAuthority('role_update')")
    @PostMapping("/update")
    public ApiResponse update() {
        return  success();
    }

    @ApiOperation(value = "删除角色管理-后端管理角色管理", notes = "删除角色管理-后端管理角色管理")
    @DeleteMapping("/delete")
    public ApiResponse delete() {
        return  success();
    }

    @ApiOperation("获取该角色拥有的权限-后端管理角色管理")
    @GetMapping("/get")
    public ApiResponse get() {
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
          if(principal instanceof User){
              User user=(User)principal;
              System.out.println("username:"+user.getUsername());
          }
        return super.success();
    }
}
